package com.yhy.server.controller;

import com.yhy.domain.UserInfo;
import com.yhy.domain.vo.UserInfoVo;
import com.yhy.server.service.SettingsService;
import com.yhy.server.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/users")
public class UserInfoController {

    @Autowired
    private UserService userService;

    @GetMapping
    public ResponseEntity users(@RequestHeader("Authorization") String token){
        return userService.findUserInfo(token);
    }

    @PutMapping
    public ResponseEntity updateUserInfo(@RequestHeader("Authorization") String token,
                                         @RequestBody UserInfo userInfo){
        return userService.updateUserInfo(userInfo,token);
    }

    /**
     * 用户资料-保存头像
     *
     * 路径:
     *     /users/header
     *
     * 参数:
     *  multipart: headPhoto
     *  Authorization: token
     */
    @PostMapping("/header")
    public ResponseEntity updateUserInfoHeader(MultipartFile headPhoto,
                                               @RequestHeader("Authorization") String token) throws IOException {
        return userService.updateUserInfoHeader(headPhoto,token);
    }

    /**
     * 互相喜欢，喜欢，粉丝 - 统计
     *
     * 接口路径：GET/users/counts
     *
     * 请求参数: 无
     *
     * 返回值:
     *      Map集合 包含下列三个返回值
     *      eachLoveCount: 互相喜欢
     *      loveCount: 喜欢
     *      fanCount: 粉丝
     */
    @GetMapping("/counts")
    public ResponseEntity counts(){
        return userService.counts();
    }

    /**
     * 互相喜欢、喜欢、粉丝、谁看过我 - 翻页列表
     *
     * 接口路径：GET/users/friends/:type
     *
     * 请求参数:
     *      type:
     *      1 互相关注
     *      2 我关注
     *      3 粉丝
     *      4 谁看过我
     *
     * 返回值: List<UserLikeListVo>
     */
    @GetMapping("/friends/{type}")
    public ResponseEntity queryUserLikeList(@PathVariable("type") Integer type,
                                            @RequestParam(defaultValue = "1") Integer page,
                                            @RequestParam(defaultValue = "10") Integer pagesize){
        return userService.queryUserLikeList(page,pagesize,type);
    }

    /**
     * 粉丝-喜欢
     *
     * 接口路径：POST/users/fans/:uid
     *
     * 请求参数:
     *      uid: 粉丝id
     *
     * 返回值: null
     */
    @PostMapping("/fans/{uid}")
    public ResponseEntity fansLike(@PathVariable("uid") Long likeUserId){
        return userService.fansLike(likeUserId);
    }

    /**
     * 喜欢-取消
     *
     * 接口路径：DELETE/users/like/:uid
     *
     * 请求参数:
     *      uid: 粉丝id
     *
     * 返回值: null
     */
    @DeleteMapping("/like/{uid}")
    public ResponseEntity dislike(@PathVariable("uid") Long likeUserId){
        return userService.dislike(likeUserId);
    }
}
